<div class="layui-fluid">
  <div class="layui-row">
    <form action="" method="post" class="layui-form layui-form-pane" lay-filter="example">
      <div class="layui-form-item">
        <input type="hidden" name="id" value="{$id}">
      </div>
      <div class="layui-form-item">
        <label for="bill_electricity_id" class="layui-form-label">
          <span class="x-red">*</span>总表
        </label>
        <div class="layui-input-inline">
          <select name="bill_electricity_id">
            {foreach $electricity as $v}
            <option value="{$v.id}" {if $v.id===$data.bill_electricity_id}selected{/if}>{$v.name}</option>
            {/foreach}
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="start_month" class="layui-form-label">
          <span class="x-red">*</span>开始月份
        </label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="start_month" name="start_month"
            value="{$data.start_month|default=date('Y-m-1',strtotime('last month'))|date='Y-m'}" required="" lay-verify="required"
            autocomplete="off">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="end_month" class="layui-form-label">
          <span class="x-red">*</span>结束月份
        </label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="end_month" name="end_month"
            value="{$data.end_month|default=date('Y-m-1',strtotime('last month'))|date='Y-m'}" required="" lay-verify="required"
            autocomplete="off">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="master_dosage" class="layui-form-label">
          <span class="x-red">*</span>总用量
        </label>
        <div class="layui-input-inline">
          <input type="text" id="master_dosage" name="master_dosage" value="{$data.master_dosage}" required="" lay-verify="required|number"
            autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="master_sum" class="layui-form-label">
          <span class="x-red">*</span>总金额
        </label>
        <div class="layui-input-inline">
          <input type="text" id="master_sum" name="master_sum" value="{$data.master_sum}" required="" lay-verify="required|number"
            autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
      </div>
    </form>
  </div>
</div>
<script>
  layui.use(['form', 'layer', 'laydate'], function () {
    $ = layui.jquery;
    var form = layui.form
      , laydate = layui.laydate
      , layer = layui.layer;

    //执行一个laydate实例
    laydate.render({
      elem: '#start_month' //指定元素
      , type: 'month'
    });

    laydate.render({
      elem: '#end_month' //指定元素
      , type: 'month'
    });

    //监听提交
    form.on('submit(save)', function (data) {
      // 发异步，把数据提交给php
      main.ajaxPost(
        {
          url: "{:url('saveWater')}",
          data: data.field,
        },
        function (data) {
          setTimeout(function () {
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //表格重载
            parent.layui.table.reload('waterGrid');
            //关闭当前frame 
            parent.layer.close(index);
          }, 1000);
        }
      )
      return false;
    });
  });
</script>